package com.albert.order.mq;

import org.apache.activemq.ScheduledMessage;
import org.springframework.jms.core.MessagePostProcessor;

import javax.jms.JMSException;
import javax.jms.Message;

/**
 * @author yangjunwei
 * @date 2021/7/14 3:47 下午
 */
public class ScheduleMessagePostProcesser implements MessagePostProcessor {
    private long delay=0L;

    public ScheduleMessagePostProcesser(long delay) {
        this.delay = delay;
    }

    @Override
    public Message postProcessMessage(Message message) throws JMSException {
        if(delay>0){
            //延时毫秒
            message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY,delay);
        }
        return message;
    }
}
